<template>
	<view>
		<scan></scan>
		<scanner></scanner>
		<sm></sm>
		<honeywell></honeywell>
		<view class="wrap">
			<u-row gutter="16">
				<u-col span="12" text-align="left">
					<view class="weikaishi2" v-html="goodsNumber+','+goodsname+','+goodsNo"></view>
				</u-col>
				<u-col span="6" text-align="center">
					<view class="weikaishi3" v-html="'Packaging:'+singlePacking"></view>
				</u-col>
				<u-col span="6" text-align="center">
					<view class="weikaishi3" v-html="'Specifications:'+goodsSpecs"></view>
				</u-col>
			</u-row>
			<u-row gutter="16" justify="space-between">
				<u-col span="6" text-align="center">
					<u-button type="primary" size="medium" @click="addBatch()">Add</u-button> 
				</u-col>
				<u-col span="6" text-align="center">
					<u-button type="primary" size="medium" @click="scanChecking()">Scan to Compare</u-button> 
				</u-col>
			</u-row>
		</view>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="6">
							<view class="weikaishi3">
								<span><u-icon name="hourglass" size="29" labelSize="14px" labelColor="#000000" label="Volume" color="#000000"></u-icon>：{{item.detailedPutvolume}}m³</span>
							</view>
						</u-col>
						<u-col span="3" text-align="right" @click="apprevokebatch(item.singleBatchnumber)">
							<view class="weikaishi">
								<u-icon name="reload" size="42" label="Revoke" color="#e84d74" label-color="#e84d74"></u-icon>
							</view>
						</u-col>
						<u-col span="3" text-align="right" @click="appstoragebatch(item.singleBatchnumber)">
							<view class="weikaishi">
								<u-icon name="plus" size="42" label="Store" color="#ffaa00" label-color="#ffaa00"></u-icon>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="8">
							<view class="weikaishi3">
								<span><u-icon name="calendar" size="29" labelSize="14px" labelColor="#000000" label="Batch"></u-icon>：{{item.singleBatchnumber}}</span>
							</view>
						</u-col>
						<u-col span="4">
							<view class="weikaishi4 lanse" @click="findGoodsfenbu(item)">
								<span><u-icon name="search" size="29" labelSize="14px" labelColor="#2b85e4" label="Goods Location" color="#2b85e4"></u-icon></span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="weikaishi3">
								<span><u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="Plan" color="#000000"></u-icon>：{{item.putNum}}</span>
							</view>
						</u-col>
						<u-col span="6"  v-if="item.putNum == item.realNum">
							<view class="weikaishi3 yiwancheng">
								<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#00c300" label="Actual" color="#00c300"></u-icon>：{{item.realNum}}</span>
							</view>
						</u-col>
						<u-col span="6" v-else>
							<view class="weikaishi3 yizuofei">
								<span><u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#e84d74" label="Actual" color="#e84d74"></u-icon>：{{item.realNum}}</span>
							</view>
						</u-col>
						<u-col span="12"  v-if="item.xianggui">
							<view class="weikaishi3">
								<span><u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="Conversion" color="#000000"></u-icon>：{{parseInt(item.putNum/item.xianggui)}}Box{{item.putNum-parseInt(item.putNum/item.xianggui)*item.xianggui}}Pack</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row >
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>Tray No.</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>Plan</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>Actual</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>Location</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>Status</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi">
								<span>Action</span>
							</view>
						</u-col>
					</u-row>
					<u-row v-for="(item1,index1) in item.list" :key="index1">
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10 weikaishi6">
								<span>{{item1.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class=" u-m-t-10 weikaishi4">
								<span>{{item1.putNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center" v-if="item1.putNum == item1.realNum">
							<view class=" u-m-t-10 weikaishi4">
								<span v-if="item1.realNum">{{item1.realNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center" v-else>
							<view class=" u-m-t-10 yizuofei weikaishi4">
								<span v-if="item1.realNum">{{item1.realNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-m-t-10 weikaishi4 huanhang">
								<span>{{item1.positionNumber}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="u-line-1 u-m-t-10" v-if="item1.singleState == 'NOT_RECEIVED'">
								<span>{{item1.singleState == 'NOT_RECEIVED' ? 'Not Stored' : 'Completed'}}</span>
							</view>
							<view class="u-line-1 u-m-t-10 yiwancheng" v-else>
								<span>{{item1.singleState}}</span>
							</view>
						</u-col>
						<u-col span="1" text-align="center" @click="problem(item1)">
							<view class="u-line-1 u-m-t-10">
								<u-icon name="question" color="#e84d74" size="34"></u-icon>
							</view>
						</u-col>
						<u-col span="1" text-align="center" @click="revoke(item1.id)" v-if="item1.singleState == 'PENDING_APPROVAL'">
							<view class=" u-m-t-10">
								<u-icon name="reload" color="#e84d74" size="36"></u-icon>
							</view>
						</u-col>
						<u-col span="1" text-align="center" @click="appstoragewoke(item1)" v-if="item1.singleState == 'NOT_RECEIVED'">
							<view class=" u-m-t-10">
								<u-icon name="plus" color="#ffaa00" size="36"></u-icon>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<u-popup v-model="popupShow" mode="center" closeable width="500rpx" height="550rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">Quantity Error</view>
			<view class=" u-m-20">
				<u-input v-model="exceptiontype" type="select" @click="getR()" placeholder="Select Exception Type"/>
			</view>
			<view class=" u-m-20">
				<u-input v-model="exceptionnodes" type="text" :border="border" placeholder="Enter Exception Description"/>
			</view>
			<view class=" u-m-20">
				<u-input v-model="realNum" type="digit" :border="border" placeholder="Enter Actual Quantity"/>
			</view>
			<view class=" u-m-20">
				<u-input v-model="positionNumber" :border="border"  placeholder="Enter Location" />
			</view>
			<view  style="height: 80rpx">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" type="primary" @click="can()">Scan</u-button>
					<u-button size="medium" @click="define()">Confirm</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="popupShow2" mode="center" closeable width="500rpx" height="500rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">Enter Location</view>
			<view class="u-m-20">
				<u-input v-model="positionNumber" :focus="focus" :border="border" placeholder="Location (Required)"/>
			</view>
			<view class="u-m-20">
				<u-input v-model="singleDateofmanufacture" :focus="focus" :border="border" placeholder="Expiry Date (Optional)"/>
			</view>
			<view  style="height: 80rpx">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" type="primary" @click="cand()">Scan</u-button>
					<u-button size="medium" @click="define2()">Confirm</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="popupShow3" mode="center" closeable width="500rpx" height="500rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">Enter Location</view>
			<view class="u-m-20">
				<u-input v-model="positionNumber" :focus="focus" :border="border" placeholder="Location (Required)"/>
			</view>
			<view class="u-m-20">
				<u-input v-model="singleDateofmanufacture" :focus="focus" :border="border" placeholder="Expiry Date (Optional)"></u-input>
			</view>
			<view style="height: 80rpx">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" type="primary" @click="canp()">Scan</u-button>
					<u-button size="medium" @click="define3()">Confirm</u-button>
				</view>
			</view>
		</u-popup>
		
		<u-popup v-model="popupShow4" mode="center" closeable width="500rpx" height="400rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">Add</view>
			<view class=" u-m-20">
				<u-input v-model="form.putNum" type="digit" :border="border"  placeholder="Enter Quantity"/>
			</view>
			<view class=" u-m-20">
				<u-input v-model="form.singleDateofmanufacture" type="select" @click="getT()" :border="border"></u-input>
			</view>
			<view class=" u-m-20">
				<u-input v-model="form.singleBatchnumber" :border="border" placeholder="Enter Batch"/>
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define4()">Confirm</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="popupShow5" mode="center" closeable width="550rpx" height="620rpx" border-radius="10">
			<view class="u-text-center u-m-t-15 weikaishi3"><u-icon name="search" size="30" labelSize="15px" labelColor="#000000" label="Goods Location"></u-icon></view>
			<u-card padding="16">
				<view class="" slot="head">
					<view class="wrap">
						<u-row>
							<u-col span="12">
								<view class="weikaishi3 lanse">
									<span v-html="storageGoodsname"></span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
				<view class="" slot="body">
					<view class="wrap">
						<u-row >
							<u-col span="3" text-align="center">
								<view class="u-line-1 u-m-t-10 weikaishi">
									<span>Location</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center">
								<view class="u-line-1 u-m-t-10 weikaishi">
									<span>Quantity</span>
								</view>
							</u-col>
							<u-col span="5" text-align="center">
								<view class="u-line-1 u-m-t-10 weikaishi">
									<span>Batch</span>
								</view>
							</u-col>
						</u-row>
						<u-row v-for="(item1,index1) in kucunlist" :key="index1">
							<u-col span="3" text-align="center">
								<view class="u-m-t-15 weikaishi3">
									<span>{{item1.positionNumber}}</span>
								</view>
							</u-col>
							<u-col span="4" text-align="center">
								<view class="u-line-1 u-m-t-15 weikaishi3">
									<span>{{item1.num}}</span>
								</view>
							</u-col>
							<u-col span="5" text-align="center">
								<view class="u-m-t-15 weikaishi4">
									<span>{{item1.goodsbatchs}}</span>
								</view>
							</u-col>
						</u-row>
					</view>
				</view>
			</u-card>
		</u-popup>
		<view>
			<u-calendar v-model="show3" mode="date" max-date="2070-01-01" @change="change" title="Select Date" confirm-text="Confirm" :weekday="['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']" :month="['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']"></u-calendar>
		</view>
		<view>
			<u-select v-model="show4" :list="typelist" @confirm="confirm"></u-select>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>
<script>
	import config from '../../config.js'
	import scan from "@/components/uni-scan/scan.vue"
	import scanner from "@/components/uni-scan/scanner.vue"
	import sm from "@/components/uni-scan/sm.vue"
	import honeywell from "@/components/uni-scan/honeywell.vue"
	export default {
		components: {
			scanner,
			scan,
			sm,
			honeywell
		},
		data() {
			return {
				dataList: [],
				storageNumber:'',
				goodsId:'',
				goodsname:'',
				goodsNumber:'',
				goodsNo:'',
				popupShow:false,
				popupShow2:false,
				popupShow3:false,
				popupShow4:false,
				popupShow5:false,
				show3:false,
				show4:false,
				realNum:'',
				tid:'',
				positionNumber:'',
				singleDateofmanufacture:'',
				form:{
					putNum:'',
					singleDateofmanufacture:'',
					singleBatchnumber:""
				},
				
				exceptionnodes:'',
				exceptiontype:'Wrong Delivery',
				typelist:[
				{
					value:"Wrong Delivery",
					label:"Wrong Delivery"
				},
				{
					value:"Rejected",
					label:"Rejected"
				},
				{
					value:"Damaged",
					label:"Damaged"
				},
				{
					value:"Lost",
					label:"Lost"
				},
			],
				singlePacking:'',
				goodsSpecs:'',
				
				storageGoodsname:'',
				kucunlist:[],
				border:true,
				focus:true
				
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			this.storageNumber = decodeURIComponent(open.storageNumber)
			this.goodsId = open.goodsId
			this.refresh()
		},
		onShow() {
			// this.refresh()
			
			uni.$off('scan');
			uni.$on('scan', (res) => {
				console.log('扫码结果1：', res.codeStr);
				this.positionNumber = res.codeStr
				this.define3()
			});
		
			uni.$off('scanner') // 每次进来先 移除全局自定义事件监听器
			uni.$on('scanner', (res) => {
				console.log('扫码结果2：', res.code);
				this.positionNumber = res.code
				this.define3()
			})
			uni.$off('sm') // 每次进来先 移除全局自定义事件监听器
			uni.$on('sm', (res) => {
				console.log('扫码结果3：', res.code);
				this.positionNumber = res.code
				this.define3()
			})
			uni.$off('honeywell') // 每次进来先 移除全局自定义事件监听器
			uni.$on('honeywell', (res) => {
				console.log('扫码结果4：', res.code);
				this.positionNumber = res.code
				this.define3()
			})
				
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {
			scanChecking() {
				let that = this
				uni.scanCode({
					success: function (res) {
						console.log('Barcode Type：' + res.scanType)
						console.log('Barcode Content：' + res.result)
						if (res.result == that.goodsNumber) {
							uni.showToast({
								title: 'Match',
								duration: 2000
							})
							that.audio_success()
						} else {
							uni.showToast({
								title: 'Not Match!',
								duration: 2000,
								icon: 'none'
							})
							that.audio_error()
						}
					}
				})
			},
			audio_success() {
				const innerAudioContext = uni.createInnerAudioContext()
				innerAudioContext.autoplay = true
				innerAudioContext.src = config.root + '/system/audio_success'
				innerAudioContext.onPlay(() => {
				  console.log('开始播放')
				})
				innerAudioContext.onError((res) => {
				  console.log(res.errMsg)
				  console.log(res.errCode)
				})
			},
			audio_error() {
				const innerAudioContext = uni.createInnerAudioContext()
				innerAudioContext.autoplay = true
				innerAudioContext.src = config.root + '/system/audio_error'
				innerAudioContext.onPlay(() => {
				  console.log('开始播放')
				})
				innerAudioContext.onError((res) => {
				  console.log(res.errMsg)
				  console.log(res.errCode)
				})
			},
			can() {
				let that = this
				uni.scanCode({
					success: function (res) {
						console.log('Barcode Type：' + res.scanType)
						console.log('Barcode Content：' + res.result)
						that.positionNumber = res.result
					}
				})
			},
			cand() {
				let that = this
				uni.scanCode({
					success: function (res) {
						console.log('Barcode Type：' + res.scanType)
						console.log('Barcode Content：' + res.result)
						that.positionNumber = res.result
						that.define2()
					}
				})
			},
			canp() {
				let that = this
				uni.scanCode({
					success: function (res) {
						console.log('Barcode Type：' + res.scanType)
						console.log('Barcode Content：' + res.result)
						that.positionNumber = res.result
						that.define3()
					}
				})
			},
			findGoodsfenbu(item) {
				this.storageGoodsname = item.goodsname
				this.$http.post('/rest/moveDisk/kucunlist', {}, {
					params: {
						goodsId: item.goodsId
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					this.kucunlist = res.data.data
					this.popupShow5 = true
				})
			},
			confirm(e) {
				this.exceptiontype = e[0].value
			},
			getR() {
				this.show4 = true
			},
			define4() {
				if (typeof this.form.putNum == 'undefined' || this.form.putNum == null || this.form.putNum == "") {
					uni.showToast({
						title: "Please enter quantity",
						icon: 'none'
					})
					return
				}

				uni.showLoading({
					title: 'Submitting'
				})
				this.$http.post('/rest/storagePut/appaddItem', {}, {
					params: {
						putNum: this.form.putNum,
						singleDateofmanufacture: this.form.singleDateofmanufacture,
						singleBatchnumber: this.form.singleBatchnumber,
						storageNumber: this.storageNumber,
						goodsId: this.goodsId
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: 'Added successfully',
							type: 'success'
						})
						setTimeout(() => {
							this.refresh()
						}, 600)
						this.popupShow4 = false
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			change(e) {
				this.form.singleDateofmanufacture = e.result
				console.log(e)
			},
			getT() {
				this.show3 = true
			},
			addBatch() {
				this.form.putNum = ''
				let year = new Date().getFullYear()
				let month = new Date().getMonth() + 1
				let day = new Date().getDate()
				this.form.singleDateofmanufacture = year + '-' + (month >= 10 ? month : '0' + month) + '-' + (day >= 10 ? day : '0' + day)
				this.popupShow4 = true
			},
			revoke(id) {
				uni.showModal({
					content: 'Confirm to revoke?',
					success: (res) => {
						if (res.confirm) {
							this.$http.post('/rest/storagePut/apprevokewoke', {}, {
								params: {
									id: id
								},
								header: {
									'Authorization': uni.getStorageSync('token')
								}
							}).then(res => {
								if (res.data.code == 200) {
									this.$refs.uToast.show({
										title: 'Revoked successfully',
										type: 'success'
									})
									setTimeout(() => {
										this.refresh()
									}, 600)
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
									setTimeout(() => {
										this.refresh()
									}, 1000)
								}
							})
						} else if (res.cancel) {
							console.log('User clicked cancel')
						}
					}
				})
			},
			appstoragewoke(item) {
				this.tid = item.id
				this.positionNumber = item.positionNumber.toLocaleUpperCase()
				this.popupShow2 = true
			},
			define2() {
				this.positionNumber = this.positionNumber.toLocaleUpperCase()

				if (!this.positionNumber) {
					uni.showToast({
						title: "Please enter location",
						icon: 'none'
					})
					return
				}

				if (!this.singleDateofmanufacture) {
					uni.showModal({
						content: 'Expiry date not filled, continue to submit?',
						success: (res) => {
							if (res.confirm) {
								this.submitStorageWithoutExpiry()
							} else if (res.cancel) {
								console.log('User cancelled submission')
							}
						}
					})
					return
				}

				this.submitStorage()
			},
			submitStorage() {
				uni.showLoading({
					title: 'Submitting'
				})
				this.$http.post('/rest/storagePut/appstoragewoke', {}, {
					params: {
						id: this.tid,
						positionNumber: this.positionNumber,
						singleDateofmanufacture: this.singleDateofmanufacture
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: 'Stored successfully',
							type: 'success'
						})
						this.audio_success()
						setTimeout(() => {
							this.refresh()
						}, 600)
						this.popupShow2 = false
					} else {
						this.audio_error()
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
					}
				})
			},
			submitStorageWithoutExpiry() {
				uni.showLoading({
					title: 'Submitting'
				})
				this.$http.post('/rest/storagePut/appstoragewoke', {}, {
					params: {
						id: this.tid,
						positionNumber: this.positionNumber
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: 'Stored successfully (Expiry date not filled)',
							type: 'success'
						})
						this.audio_success()
						setTimeout(() => {
							this.refresh()
						}, 600)
						this.popupShow2 = false
					} else {
						this.audio_error()
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
					}
				})
			},
			problem(item) {
				this.tid = item.id
				this.positionNumber = item.positionNumber.toLocaleUpperCase()
				this.exceptionnodes = ''
				this.popupShow = true
			},
			define() {
				if (typeof this.realNum == 'undefined' || this.realNum == null || this.realNum == "") {
					uni.showToast({
						title: "Please enter actual quantity",
						icon: 'none'
					})
					return
				}

				this.positionNumber = this.positionNumber.toLocaleUpperCase()

				if (typeof this.positionNumber == 'undefined' || this.positionNumber == null || this.positionNumber == "") {
					uni.showToast({
						title: "Please enter location",
						icon: 'none'
					})
					return
				}

				uni.showLoading({
					title: 'Submitting'
				})
				this.$http.post('/rest/storagePut/appstoragewoke', {}, {
					params: {
						id: this.tid,
						realNum: this.realNum,
						positionNumber: this.positionNumber,
						exceptionnodes: this.exceptionnodes,
						exceptiontype: this.exceptiontype,
						singleDateofmanufacture: this.singleDateofmanufacture
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: 'Operation successful',
							type: 'success'
						})
						this.audio_success()
						setTimeout(() => {
							this.refresh()
						}, 600)
						this.popupShow = false
					} else {
						this.audio_error()
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
					}
				})
			},
			appstoragebatch(singleBatchnumber) {
				this.singleBatchnumber = singleBatchnumber
				this.positionNumber = ''
				this.singleDateofmanufacture = ''
				this.popupShow3 = true
			},
			define3() {
				this.positionNumber = this.positionNumber.toLocaleUpperCase()

				if (!this.positionNumber) {
					uni.showToast({
						title: "Please enter location",
						icon: 'none'
					})
					return
				}

				if (!this.singleDateofmanufacture) {
					uni.showModal({
						content: 'Expiry date not filled, continue to submit?',
						success: (res) => {
							if (res.confirm) {
								this.submitBatchWithoutExpiry()
							} else if (res.cancel) {
								console.log('User cancelled submission')
							}
						}
					})
					return
				}

				this.submitBatch()
			},
			submitBatch() {
				uni.showLoading({
					title: 'Submitting'
				})
				this.$http.post('/rest/storagePut/appstoragebatch', {}, {
					params: {
						goodsId: this.goodsId,
						storageNumber: this.storageNumber,
						singleBatchnumber: this.singleBatchnumber,
						positionNumber: this.positionNumber,
						singleDateofmanufacture: this.singleDateofmanufacture
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: 'Stored successfully',
							type: 'success'
						})
						this.audio_success()
						setTimeout(() => {
							this.refresh()
						}, 600)
						this.popupShow3 = false
					} else {
						this.audio_error()
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
					}
				})
			},
			submitBatchWithoutExpiry() {
				uni.showLoading({
					title: 'Submitting'
				})
				this.$http.post('/rest/storagePut/appstoragebatch', {}, {
					params: {
						goodsId: this.goodsId,
						storageNumber: this.storageNumber,
						singleBatchnumber: this.singleBatchnumber,
						positionNumber: this.positionNumber
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: 'Stored successfully (Expiry date not filled)',
							type: 'success'
						})
						this.audio_success()
						setTimeout(() => {
							this.refresh()
						}, 600)
						this.popupShow3 = false
					} else {
						this.audio_error()
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
					}
				})
			},
			apprevokebatch(singleBatchnumber) {
				uni.showModal({
					content: 'Confirm to revoke all?',
					confirmText: 'Confirm',
					cancelText: 'Cancel',
					success: (res) => {
						if (res.confirm) {
							this.$http.post('/rest/storagePut/apprevokebatch', {}, {
								params: {
									goodsId: this.goodsId,
									storageNumber: this.storageNumber,
									singleBatchnumber: singleBatchnumber
								},
								header: {
									'Authorization': uni.getStorageSync('token')
								}
							}).then(res => {
								if (res.data.code == 200) {
									this.$refs.uToast.show({
										title: 'Revoked successfully',
										type: 'success'
									})
									setTimeout(() => {
										this.refresh()
									}, 600)
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
									setTimeout(() => {
										this.refresh()
									}, 1000)
								}
							})
						} else if (res.cancel) {
							console.log('User clicked cancel')
						}
					}
				})
			},
			refresh() {
				uni.showLoading({
					title: 'Loading...'
				})
				this.$http.post('/rest/storagePut/applistbatchwork', {}, {
					params: {
						storageNumber: this.storageNumber,
						goodsId: this.goodsId
					},
					header: {
						'Authorization': uni.getStorageSync('token')
					}
				}).then(res => {
					uni.hideLoading()
					this.dataList = res.data.data
					console.log(res);
					for (let item1 of res.data.data) {
						if (this.goodsname == '') {
							this.goodsname = item1.goodsname
							this.goodsNumber = item1.goodsNumber
							this.goodsNo = item1.goodsNo
							this.singlePacking = item1.singlePacking
							this.goodsSpecs = item1.goodsSpecs
							return
						}
					}
				})
			}
		}
	}
</script>
<style lang="scss">
	.weikaishi2 {
		margin: 20rpx 20rpx 5rpx 20rpx;
	}
	.huanhang {
		word-break: break-all;
	}
</style>